<?php
//require_once("connect_sql.php");
require_once '/home/ubuntu/webserver/workerman-tcp_server/vendor/workerman/mysql-master/src/Connection.php';

if (!isset($_POST['submit'])) {
    return;
}
if (!empty($_POST['time'])) {
    $time = $_POST['time'];
} else {
    echo "参数错误";
    return;
}
if (!empty($_POST['devId'])) {
    $devId = $_POST['devId'];
} else {
    echo "参数错误";
    return;
}

$db = new \Workerman\MySQL\Connection('127.0.0.1', 'port', 'root', 'li999888', 'module_db');

$st = $time;
$et = date("Y-m-d", strtotime("+1 day", strtotime($time)));
//echo "$st\n$et\n";
$sql = "select is_client,date,data from original_data where dev_id=$devId and date > '$st' and date < '$et' order by date;";
//$result = $db->select('date,is_client,data')->from('original_data')->where("dev_id=$devId")->query()
$result = $db->query($sql);
//var_dump($result);
//return;
if (empty($result)) {
    echo "<h3>设备<span style='color:red'>{$devId}</span>于<span style='color:red'>{$time}</span>没有数据。</h3>";
    return;
} else {
    echo "<h3>设备<span style='color:red'>{$devId}</span>于<span style='color:red'>{$time}</span>的数据：</h3>";
    foreach ($result as $row) {
        if ($row['is_client']) {
            echo "[" . $row['date'] . "][RECV]:" . $row['data'] . "<br/>";
        } else {
            echo "[" . $row['date'] . "][SEND]:" . $row['data'] . "<br/>";
        }
    }
}
